// 先验证有没有登录
(()=>{
  //1.获取地址栏中数据 ?email=ding@qq.com&uid=1
   //var data=location.search
   //alert(location.href);
   //截取字符串中邮箱地址
   //var a=data.split('=');
  //alert(a[1]);
  let obj=new URLSearchParams(location.search);
  // console.log(obj);
  let uname = obj.get("uname");
  // alert(uname); 
  //1.创建对象
   let xhr = new XMLHttpRequest();
   //2.保存session数据添加属性#在客户端加密保存session数据
   xhr.withCredentials = true;
   //3.指定接收数据函数
   xhr.onreadystatechange = ()=> {
     //6.接收数据
     if(xhr.readyState==4 && xhr.status==200) {
      // console.log(xhr.responseText);
       let obj=JSON.parse(xhr.responseText);
       
       // console.log(obj);
       // alert(rs);
       if(obj.code<=0) {
         let mymusic_prompt = document.getElementById("mymusic_prompt");
         let mymusic = document.getElementById("mymusic");
         let user_img = document.getElementById("user_img");
         let user_name = document.getElementById("user_name");
         mymusic_prompt.style.display = "block";
         mymusic.style.display = "none";
         user_img.style.display = "none";
         user_name.innerHTML = "";
       }else{
        let mymusic_prompt = document.getElementById("mymusic_prompt");
        let mymusic = document.getElementById("mymusic");
        let user_img = document.getElementById("user_img");
        let user_name = document.getElementById("user_name");
        let editPre = document.getElementById("editPre");
        let index = document.getElementById("index");
        mymusic_prompt.style.display = "none";
        mymusic.style.display = "block";
        user_img.style.display = "block";
        user_img.src = obj.data.user_photo;
        user_name.innerHTML = obj.data.uname;
        editPre.href = `http://127.0.0.1:8848/html/personal.html?uname=${obj.data.uname}`;
        index.href = `http://127.0.0.1:8848/html/index.html?uname=${obj.data.uname}`;
       }
     }
   }
   //4.指定服务器地址
   let url =`http://127.0.0.1:8848/user/v1/search?uname=${uname}`;
   xhr.open("GET",url,true);
   //5.发送请求
   xhr.send();
})();